// pages/activity/activity.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    unlogin: true,
    loginstatus:false,
  },
  joinUs: function (e) {
    var that = this;
    var formid = e.detail.formId;
    wx.request({
      url: app.siteInfo.siteroot + 'saveformid',
      method: "post",
      data: {
        uid: app.siteInfo.uid,
        formid: formid
      },
      success: function (res) {

      }
    })
    var title= that.data.activity.title;
    
    wx.navigateTo({
      url: '/pages/joinUs/joinUs?source=activity&source_txt=来自活动'+title+'联系我们',
    })
    
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    app.confirmPid(function(){
      if (options.id) {
        var id = options.id;
        that.setData({
          id: options.id
        })
        wx.request({
          url: app.siteInfo.siteroot + 'getactivity',
          method: "post",
          data: {
            uid: app.siteInfo.uid,
            pid: app.siteInfo.pid,
            com_part_id: app.siteInfo.com_part_id,
            id: id
          },
          success: function (res) {
            var article = res.data.content
            WxParse.wxParse('article', 'html', article, that, 0);
            res.data.content = article;
            that.setData({
              activity: res.data
            })
          }
        })
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    wx.request({
      url: app.siteInfo.siteroot + 'relay',
      method: "post",
      data: {
        uid: app.siteInfo.uid,
        pid: app.siteInfo.pid,
        replaysource:"activity"
      },
      success: function (res) { }
    })
    return {
      title: that.data.activity.title,
      path: "/pages/activity/activity?share_card_id=" + app.siteInfo.pid + "&shareid=" + app.siteInfo.uid+"&page=activity&id="+that.data.id,
      success: function (a) {
        wx.request({
          url: app.siteInfo.siteroot + 'relay',
          method: "post",
          data: {
            uid: app.siteInfo.uid,
            pid: app.siteInfo.pid
          },
          success: function (res) { }
        })
      },
      fail: function (a) { }
    };
  }
})